package com.netease.xone.itemview;

import protocol.meta.AppImage;
import Utils.StackTraceUtil;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.netease.log.NTLog;
import com.netease.xone.R;
import com.netease.xone.image.ImageViewTouch;


public class RenderImageBrowser {
    private static final String TAG = RenderImageBrowser.class.getSimpleName();

    private int mWidth;
    private View mRoot;
    private ImageViewTouch mImage;
    
    private LinearLayout mTip;
    private TextView mTitle;
    private TextView mContent;
    
    public RenderImageBrowser(View v) {
        mRoot = v;
        mWidth = v.getContext().getResources().getDisplayMetrics().widthPixels;
        
        mImage = (ImageViewTouch)v.findViewById(R.id.image);
        mTip = (LinearLayout)v.findViewById(R.id.tip);
        mTitle = (TextView)v.findViewById(R.id.title);
        mContent = (TextView)v.findViewById(R.id.content);
        
        mImage.allowTouch(true);
    }

    public void renderView(Context context, AppImage appImage) {
        NTLog.d(TAG, StackTraceUtil.getMethodName());
        
        if (null != appImage && !TextUtils.isEmpty(appImage.getUrl())) {
            mRoot.setVisibility(View.VISIBLE);
        } else {
            mRoot.setVisibility(View.GONE);
            return;
        }
       
        String url = null;
        url = appImage.getUrl();
        mImage.setServerClipSize(mWidth, 0);
        mImage.setLoadingImage(url);
        mImage.setTag(appImage);
        
        if (TextUtils.isEmpty(appImage.getTitle()) && TextUtils.isEmpty(appImage.getDesc())) {
            mTip.setVisibility(View.GONE);
        }
        
        mTitle.setText(appImage.getTitle());
        mContent.setText(appImage.getDesc());
    }
}
